<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse"
            text-color="#ffffff" active-text-color="#2468F1" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.id">
                        <template slot="title">
                            <!-- <i :class="item.icon"></i> -->
                            <img :src="item.url" class="icon_iv"/>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.id">
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i"
                                    :index="threeItem.index">{{threeItem.title}}</el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.id">{{ subItem.title
                                }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from './bus';
import homeicon from '../../assets/img/zichan.png';
import menuicon from '../../assets/img/menu.png';

export default {
    data() {
        return {
            collapse: false,
            items: [
                {
                    icon: 'el-icon-house',
                    url: homeicon,
                    title: '预警结果数据',
                    id: 1,
                    index:'1',
                    subs: [
                        {
                            title: '供应链预警',
                            id: 11,
                            index: 'firstView',

                        },
                        {
                            index: 'aiJianceView',
                            id: 12,
                            title: 'AI应用风险信息融合检测'
                        },
                        {
                            index: 'quexianList',
                            id: 13,
                            title: '算法缺陷预警'
                        },
                        {
                            index: 'gongjiView',
                            id: 14,
                            title: '新型攻击风险预警'
                        },
                        {
                            index: 'tuanhuoView',
                            id: 15,
                            title: '团伙预警'
                        }
                    ]
                },
                // {
                //     icon: 'el-icon-s-data',
                //     title: '知识图谱',
                //     id: 2,
                //     index:'2',
                //     subs: [
                //         {
                //             title: '知识图谱展示',
                //             index: 'zhishiView',
                //             id: 21,
                //         }
                //     ]
                // },
                {
                    icon: 'el-icon-menu',
                    url: menuicon,
                    title: 'AB测试',
                    id: 4,
                    index:'4',
                    subs: [
                        {
                            title: '实验管理',
                            index: 'abTestView',
                            id: 41,
                        }
                    ]
                },
                {
                    icon: 'el-icon-menu',
                    url: menuicon,
                    title: '任务统计',
                    id: 3,
                    index:'3',
                    subs: [
                        {
                            title: '任务统计看板',
                            index: 'taskList',
                            id: 31,
                        }
                    ]
                }
                
            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    }
};
</script>

<style>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.icon_iv{
    width: 20px;
    height: 20px;
    margin-right: 5px;
}
.el-table thead{
    color: #606266;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.el-table--striped .el-table__body tr.el-table__row--striped td{
    background: #f5f7fa
}
.el-message-box__title{
    border-left: #2468f2 solid 4px;
    padding-left: 6px;
    border-radius: 2.5px;
    color: #303133;
    font-weight: bold;
    font-size: 16px;
}
.sidebar-el-menu{
    background-color: #2c3951; /* 你想要的颜色 */
}
.el-submenu__title{
    background-color: #2c3951; /* 你想要的颜色 */
}
.el-menu-item {
    background-color: #2c3951; /* 你想要的颜色 */
}
.el-menu-item is-active {
    background-color: #ffffff; /* 你想要的颜色 */
}
.el-menu-item.is-active{
    background-color: #ffffff; /* 你想要的颜色 */
    border: 1px solid #2468F1;
}
.el-button--primary{
    background-color: #2468F2;
    border-color: #2468F2;
}
.el-submenu__title i{
    color: white;
}
.el-submenu .el-menu-item{
    color: white;
}
.el-submenu__title *{
    color: white;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 230px;
}
.el-menu-item:hover {
    background-color: #515E78 !important; /* 你想要的悬停颜色 */
}
.el-submenu :hover {
    background-color: #515E78 !important; /* 你想要的悬停颜色 */
}
.el-menu-item.is-active :hover{
    background-color: #ffffff !important; /* 你想要的颜色 */
}
.el-menu-item is-active :hover{
    background-color: #ffffff !important; /* 你想要的颜色 */
}
.sidebar>ul {
    height: 100%;
}
</style>
